#include "FileIOThread.h"


FileIOThread::FileIOThread()
{
	this->SetState(THREAD_INITIALIZING);
	this->m_ThreadName = "FileWorker";
	if(Init())
	{
		this->SetState(THREAD_READY);
	}

}

FileIOThread::FileIOThread(char* name)
{
	this->SetState(THREAD_INITIALIZING);
	this->m_ThreadName = name;
	if(Init())
	{
		this->SetState(THREAD_READY);
	}
}

FileIOThread::~FileIOThread()
{

}

bool FileIOThread::OnInit()
{
	return true;
}

bool FileIOThread::OnWork()
{
	return true;
}

bool FileIOThread::OnWorkFinished()
{
	return true;
}

void FileIOThread::OnThreadEvent()
{
	
}

unsigned int WINAPI FileIOThreadProcedure(LPVOID p_param)
{
	FileIOThread* p_worker = (FileIOThread*)p_param;
	if(p_worker)
	{
		p_worker->SetState(THREAD_WAITING);
		for(;;)
		{
			WaitForSingleObject(p_worker->m_ThreadWorkSemaphore,INFINITE);
			p_worker->SetState(THREAD_JOB_WORKING);			
			if(!p_worker->OnWork())
			{
				continue;
			}
			if(!p_worker->OnWorkFinished())
			{
				continue;
			}
		}
	}
	return 0;
}